package cn.edu.scau.sec.caixiaoqing.client;

import cn.edu.scau.sec.caixiaoqing.composite.securitycomposite.AtomSecurityTestCase;
import cn.edu.scau.sec.caixiaoqing.composite.securitycomposite.SecurityTestCase;
import cn.edu.scau.sec.caixiaoqing.composite.securitycomposite.SecurityTestSuite;
import cn.edu.scau.sec.caixiaoqing.composite.transparentcomposite.AtomTransparentTestCase;
import cn.edu.scau.sec.caixiaoqing.composite.transparentcomposite.TransparentTestCase;
import cn.edu.scau.sec.caixiaoqing.composite.transparentcomposite.TransparentTestSuite;

public class Client {

    public static void main(String[] args) {

        System.out.println("=========================================================================");
        System.out.println("安全组合模式：");
        testSecurityTestCase();

        System.out.println();

        System.out.println("=========================================================================");
        System.out.println("透明组合模式：");
        testTransparentTestCase();
    }

    private static void testSecurityTestCase(){

        System.out.println("-------------------------------原子测试-----------------------------------");

        SecurityTestCase first_AtSeTestCase = new AtomSecurityTestCase(1,1,2);
        printTestResult(first_AtSeTestCase.test());

        SecurityTestCase second_AtSeTestCase = new AtomSecurityTestCase(2,1,3);
        printTestResult(second_AtSeTestCase.test());

        SecurityTestCase third_AtSeTestCase = new AtomSecurityTestCase(2,1,4);
        printTestResult(third_AtSeTestCase.test());

        System.out.println("-------------------------------组合测试-----------------------------------");

        SecurityTestSuite first_SeTestSuite = new SecurityTestSuite();
        first_SeTestSuite.add(first_AtSeTestCase);
        first_SeTestSuite.test();
        System.out.println("第一个组合测试添加了第一个原子测试用例后测试完成。");
        System.out.println("-------------------------------------------------------------------------");

        first_SeTestSuite.add(second_AtSeTestCase);
        first_SeTestSuite.test();
        System.out.println("第一个组合测试添加了第一个和第二个原子测试用例后的组合测试用例测试完成。");
        System.out.println("-------------------------------------------------------------------------");

        SecurityTestSuite second_SeTestSuite = new SecurityTestSuite();
        second_SeTestSuite.add(third_AtSeTestCase);
        second_SeTestSuite.test();
        System.out.println("第二个组合测试用例测试完成。");
        System.out.println("-------------------------------------------------------------------------");

        first_SeTestSuite.add(second_SeTestSuite);
        first_SeTestSuite.test();
        System.out.println("第一个组合测试用例添加了第二个组合测试用例后，第一个组合测试用例运行完毕。");
        System.out.println("-------------------------------------------------------------------------");

        first_SeTestSuite.remove(second_SeTestSuite);
        first_SeTestSuite.test();
        System.out.println("第一个组合测试用例删除了第二个组合测试用例后，第一个组合测试用例运行完毕。");
        System.out.println("=========================================================================");
    }

    private static void testTransparentTestCase(){

        System.out.println("-------------------------------原子测试-----------------------------------");

        TransparentTestCase first_AtTrTestCase = new AtomTransparentTestCase(1,1,2);
        printTestResult(first_AtTrTestCase.test());

        TransparentTestCase second_AtTrTestCase = new AtomTransparentTestCase(2,1,3);
        printTestResult(second_AtTrTestCase.test());

        TransparentTestCase third_AtTrTestCase = new AtomTransparentTestCase(2,1,4);
        printTestResult(third_AtTrTestCase.test());

        System.out.println("-------------------------------组合测试-----------------------------------");


        TransparentTestCase first_TrTestSuite = new TransparentTestSuite();
        first_TrTestSuite.add(first_AtTrTestCase);
        first_TrTestSuite.test();
        System.out.println("第一个组合测试添加了第一个原子测试用例后测试完成。");
        System.out.println("-------------------------------------------------------------------------");

        first_TrTestSuite.add(second_AtTrTestCase);
        first_TrTestSuite.test();
        System.out.println("第一个组合测试添加了第一个和第二个原子测试用例后的组合测试用例测试完成。");
        System.out.println("-------------------------------------------------------------------------");

        TransparentTestCase second_TrTestSuite = new TransparentTestSuite();
        second_TrTestSuite.add(third_AtTrTestCase);
        second_TrTestSuite.test();
        System.out.println("第二个组合测试用例测试完成。");
        System.out.println("-------------------------------------------------------------------------");

        first_TrTestSuite.add(second_TrTestSuite);
        first_TrTestSuite.test();
        System.out.println("第一个组合测试用例添加了第二个组合测试用例后，第一个组合测试用例运行完毕。");
        System.out.println("-------------------------------------------------------------------------");

        first_TrTestSuite.remove(second_TrTestSuite);
        first_TrTestSuite.test();
        System.out.println("第一个组合测试用例删除了第二个组合测试用例后，第一个组合测试用例运行完毕。");
        System.out.println("=========================================================================");
    }

    private static void printTestResult(boolean flag){
        if (flag) System.out.println("测试通过。");
        else System.out.println("测试没有通过，请检查测试数据和被测试的方法，查找测试没有通过的原因。");
    }
}
